package cn.cool.netty.nio.buffer;

import java.nio.ByteBuffer;

public class TestByteBufferSplit {
    public static void main(String[] args) {
        ByteBuffer buffer = ByteBuffer.allocate(64);
        buffer.put("hello,world\nI'm zhangsan\nHo".getBytes());
        split(buffer);
        buffer.put("w are You?\n".getBytes());
        split(buffer);
    }

    private static void split(ByteBuffer buffer) {
        // 开启读模式
        buffer.flip();
        for (int i = 0; i < buffer.limit(); i++) {
            if (buffer.get(i) == '\n') {
                int length = i - buffer.position() + 1;
                ByteBuffer allocation = ByteBuffer.allocate(length);
                for (int j = 0; j < length; j++) {

                }
            }
        }
        buffer.compact();
    }
}






























